package net.ru.topdog.lunchy.main;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

public class MainView implements MainViewObserverInterface {
	private Shell shell;
	private MainControllerInterface controller;
	private MainModelInterface model;
	
	public MainView(MainControllerInterface controller, MainModelInterface model) {
		this.controller=controller;
		this.model=model;
		model.registerMainViewObserver(this);// This view is a model subscriber.
	}
	
	/**
	 *  Create SWT contents  of the MainView
	 * @wbp.parser.entryPoint
	 */
	public void createMainView(){
		shell = new Shell();
		shell.setSize(450, 300);
		shell.setText("SWT Application");
		
		
		//______________________btnToOpenWindowEditMenu___________________________
		Button btnToOpenWindowEditMenu = new Button(shell, SWT.NONE);
		
		btnToOpenWindowEditMenu.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				controller.openWindowEditMenu();
				
				
			}
		});

		btnToOpenWindowEditMenu.setBounds(10, 31, 75, 25);
		btnToOpenWindowEditMenu.setText("Edit menu");
		//______________________btnToOpenWindowEditMenu___________________________end
	}
	
	public void runApplication(){
		Display display = Display.getDefault();
		//createMainView(); // May be to do like this here?..
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

@Override
	//This view subscribed to updates of the model
	public void updateMainView() {
		// UpDate view...
		// If the model has been updated or smth
		shell.setVisible(model.isActivity());
		shell.setFocus();
		
	}
}
